home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / math / eval.zip / EVAL.DOC < prev    next >
Text File  |  1996-05-14  |  8KB  |  234 lines

  1. Eval v.1.0 for Clarion for Dos 3.1
  2. (CL) CopyLeft 1996, Petr Langer
  3. No Rights Reserved
  4.  
  5.                         What is it ?
  6.                         ------------
  7. A small utility for evaluating mathematical expressions in CfD 3.1.
  8. Have you ever needed to evaluate any mathematical expression defined by user,
  9. but there were no easy way to do that ?
  10. Then this utility may be useful for you.
  11.  
  12.                         How to use it
  13.                         -------------
  14. Eval is defined as Function and called with two parameters.
  15. The first one is String(200) variable containing expression to evalute.
  16. The second one is Byte variable "passed by address", which returns
  17. an error code if Eval is not able to correctly finish it's job.
  18. Eval returns result of computing as a type of Real.
  19.  
  20. Example:
  21. --------------------------------------------------------------------------
  22.         Program
  23.          map
  24.            Module('Eval')
  25.              Eval(STRING,*BYTE),REAL
  26.            .
  27.          .
  28.  
  29. Expr      String(20)
  30. Err_code  Byte
  31. Result    Real
  32.  
  33.   Code
  34.     Expr = 'Sin(Pi/2)'
  35.     Result = Eval(Expr,Err_code)
  36.     if ~Err_code                        ! Err_code = 0 if everything is OK
  37.       ...                               ! code for error handling
  38.       ...                               ! Result = 0
  39.     else
  40.       show(,,Result,@n22.10)
  41.     .
  42. --------------------------------------------------------------------------
  43. You have to add this line to the Project ==> Module
  44.   Module Name : %clapfx%eval.lib
  45.   Module Type : Object/Library  (Linker)
  46.  
  47.  
  48. I included a very simple program called CALC.CLA
  49.  
  50.  
  51.                 Functions defined in Eval
  52.                 -------------------------
  53. With one parameter :
  54.  SIN(x)  - Sine
  55.  COS(x)  - Cosine
  56.  TAN(x)  - Tangens
  57.  COTG(x) - Cotangens
  58.  ASIN(x) - ArcSine
  59.  ACOS(x) - ArcCosine
  60.  ATAN(x) - ArcTangens
  61.  EXP(x)  - e^x ( e is the Euler's number )
  62.  LOGE(x) - natural logarithm
  63.  LOG10(x)- decadical loagarithm
  64.  ABS(x)  - absolute value
  65.  INT(x)  - integer part
  66.  SQRT(x) - square root
  67.  SIGN(x) - Signum ( -1 if x<0, 0 if x=0, 1 if x>0 )
  68.  FACT(x) - Factorial ( x! )
  69.  INV(x)  - Inversion ( 1/x )
  70.  
  71. With two parameters:
  72.  BAND(x1,y)      - Bitwise AND
  73.  BOR(x1,y)       - Bitwise OR
  74.  BXOR(x1,y)      - Bitwise XOR
  75.  BSHIFT(x,i)     - Bitwise SHIFT
  76.  
  77.  
  78.                         Operators
  79.                         ---------
  80.  x+y     - addition
  81.  x-y     - substraction
  82.  x*y     - multiplication
  83.  x/y     - division
  84.  x^y     - power
  85.  x**y    - power (the same as ^)
  86.  
  87.  
  88.                         Constants
  89.                         ---------
  90.  Pi      - Pi = 3.14159265358979323846
  91.  e       - Euler's number = 2.71828182846
  92.  
  93.  
  94. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  95. !!! x,y,i  may be either numbers, constants or expressions !!!
  96. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  97.  
  98.                         Error codes:
  99.                         ------------
  100.   0      - everything is OK, computed result returned
  101.   1      - function not followed by left bracket
  102.   2      - contains invalid function
  103.   3      - contains invalid charcter
  104.   4      - too few right brackets
  105.   5      - too few left brackets
  106.   6      - TAN not defined (i.e. TAN(Pi/2))
  107.   7      - COTG not defined (i.e. COTG(0))
  108.   8      - Fact(x) not defined : x < 0
  109.   9      - Fact(x) not defined : x is a decimal number
  110.  10      - Inv(x) not defined : x = 0
  111.  11      - Division by zero
  112.  12      - LogE(x) or Log10(x) not defined : x = 0
  113.  13      - Wrong number of parameters
  114.  
  115. Error codes 1..13 return zero as a result
  116.  
  117. Note: When I used Tan(pi/2) and similar non-defined functions (with Pi)
  118.       I had problems to detect these to provide the 6 & 7 errors.
  119.       This is caused by Cos(Pi/2) which doesn't return the exact value
  120.       of zero . So I decided to return these errors, when the result
  121.       of Sin(x) or Cos(x) is lower then 10e-15.
  122.       I havent't found a better way...
  123.  
  124.                         Examples
  125.                         --------
  126.  
  127.   Result = Eval('3+4*5*(1-sin(30*pi/180))-fact(sqrt(25)-2)*bshift(3,-1)',Err)
  128.      *** [ Result=7  ; Err=0] ***
  129. ----------------------------------------------------------------------------
  130.  
  131.   Expr = '3+4*5*(1-sin(30*pi/180))-fact(sqrt(25)-2)*bshift(3,-1)'
  132.   Result = Eval(Expr,Err)
  133.      *** [ Result=7  ; Err=0] ***
  134.  
  135. ----------------------------------------------------------------------------
  136.  
  137.   Result = Eval('Band(14,5)^2*Log10(100)-2*Inv(Tan(pi/4))',Err)
  138.      *** [ Result=30  ; Err=0] ***
  139.  
  140. ----------------------------------------------------------------------------
  141.  
  142.    * if 1st condition = 'Yes'
  143.    *   Expr = '(1'
  144.    * else
  145.    *   Expr = '(0'
  146.    * .
  147.    *
  148.    * if 1st Logical operator = 'AND'
  149.    *   Expr = Clip(Expr) & '*'
  150.    * else                               ! else
  151.    *   Expr = Clip(Expr) & '+'          !      OR
  152.    * .
  153.    *
  154.    * if 2nd condition = 'Yes'
  155.    *   Expr = Clip(Expr) & '1)'
  156.    * else
  157.    *   Expr = Clip(Expr) & '0)'
  158.    * .
  159.    *
  160.    * if 2nd Logical operator = 'AND'
  161.    *   Expr = Clip(Expr) & '*'
  162.    * else                               ! else
  163.    *   Expr = Clip(Expr) & '+'          !      OR
  164.    * .
  165.    *
  166.    * if 3rd condition = 'Yes'
  167.    *   Expr = Clip(Expr) & '1'
  168.    * else
  169.    *   Expr = Clip(Expr) & '0'
  170.    * .
  171.    *
  172.    *  Expr now looks like '(1+0)*1' or '(1*0)*1' or .... whatever
  173.  
  174.  
  175.   Result = Eval(Expr,Err)
  176.      *** [Result=0/1 depending on Expr; Err=0] ***
  177.  
  178. ----------------------------------------------------------------------------
  179.  
  180.   Result = Eval('5*3+',Err)
  181.      *** [Result=0; Err=13] ***
  182.  
  183. ----------------------------------------------------------------------------
  184.  
  185.   Result = Eval('5*Cos(Pi+3',Err)
  186.      *** [Result=0; Err=4] ***
  187.  
  188. ----------------------------------------------------------------------------
  189.   etc...etc...etc...
  190.  
  191.  
  192.  
  193. I think that's all I want to say about functionality...
  194. And now.....
  195.                             ****************
  196. This tool is provided AS IS. I disclaim all warranties to this software
  197. or documentation, whether express or implied.
  198. There should be no malfunctions caused by Eval, but use it AT YOUR OWN RISK.
  199.  
  200.                             ****************
  201. As you may have noticed, there is no Copyright for this software.
  202.  
  203. Why?
  204. I don't like when a programer makes utility primary for own usage, then
  205. finds out that it works pretty well and decides to offer it as a shareware
  206. with a registration fee of $xx  which you have to pay if you want to us it.
  207. I'm sorry, but I don't feel it to be a good idea...
  208. Of course, I'd like to get some money (I am a student), but I think
  209. it's much better to make commercial software for companies for profit
  210. (as I do).
  211.  
  212. So, if you don't belong to the group I mentioned above, use this software
  213. as long as you like it and find it useful. I give you ALL rights for
  214. using it. You may use it either in your commercial software without any
  215. registering. Generally said, do really WHATEVER you want with it.
  216. If desired, the source code is also available !
  217.  
  218. Otherwise, if you do belong there, you have to contact me.
  219.  
  220.                     ******** Finally Finish ********
  221. Do you have any question, suggestion, wish, comment, reproachful word
  222. or something you'd like to tell me ?
  223. Feel free to write to me.
  224. Excuse my English. I hope you understand everything...
  225.  
  226. Address :
  227.                    Petr Langer
  228.                    Jiráskova 1815
  229.            755 01  Vsetín
  230.                 CZECH REPUBLIC
  231.  
  232. e-mail :    p.langer@zlin.vutbr.cz       or
  233.             langer@leo1.zlin.vutbr.cz
  234.